#define ttree_decl_$(TA_DECL)_cxx
#include "ttree_declaration.h"
#define ttree_decl ttree_decl_$(TA_DECL)
#include "stdlib.h"
//void print_usage(const char *a)
//{
//   printf("Usage:\n./%s file.root ttree_name\n",a);
//}
extern "C" {
void *get_ttree_$(TA_DECL)(const char* file_name,const char*tree_name)
{
   TFile *f = new TFile(file_name,"r");
   if (!f || f->IsZombie())
   {
       printf("file not found or corrupt\n");
//       print_usage(file_name);
       exit(11);
   }
   TTree *tree = (TTree *) f->Get(tree_name);
   if  (!tree)
   {
       printf("ttree not found in file\n");
       exit(12);
   }
   ttree_decl *t = new ttree_decl();
   t->Init(tree);
   return ((void*) t);
}

long long n_of_ttree_$(TA_DECL)(void*t)
{
    ttree_decl *h = (ttree_decl*) t;
    return h->fChain->GetEntries();
}
void fill_$(TA_DECL)(void *t, Long64_t n)
{
    ttree_decl *h = (ttree_decl*) t;
    h->fChain->GetEntry(n);
}
}
